var webpack = require('webpack');
var path = require('path');
var proxy = require('http-proxy-middleware');

module.exports = {
    // 1.入口文件
    entry:'./src/App.js',
    // 2.出口文件
    output:{
        publicPath:'./', // 编译以后的文件存放路径
        filename:'bundle.js' // 编译以后文件的名称
    },
    module:{ // 模块操作
        loaders:[ // webpack的核心基础操作就是 loaders,也就是加载器
            {
                test: /\.js$/,
                loader:"babel-loader",
                query:{
                    presets:['es2015','react','stage-0']
                }
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
                loader: 'file-loader'
            },
            {
                test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
                loader: 'file-loader',
                query: {
                  name: '[name].[ext]?[hash]'
                }
              },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            }
        ]
    },
    devServer:{
        proxy: {
            '/api':{
                target:'http://api.douban.com',
                pathRewrite: {'^/api': '/'},
                changeOrigin: true
            }
        }
    }
}

if (process.env.NODE_ENV === 'production') {
    module.exports.devtool = '#source-map'
    // http://vue-loader.vuejs.org/en/workflow/production.html
    module.exports.plugins = (module.exports.plugins || []).concat([
      new webpack.DefinePlugin({
        'process.env': {
          NODE_ENV: '"production"'
        }
      }),
      new webpack.optimize.UglifyJsPlugin({
        compress: {
          warnings: false
        }
      })
    ])
  }